package com.qf.smartdevice.sql.providers;

import com.alibaba.druid.util.StringUtils;

public class UserSqlProvider {
    public String getQueryByNameAndStaus(String username,Integer status){
        StringBuffer stringBuffer=new StringBuffer("select * from users where");
        boolean isNeedAnd=false;
        if (!StringUtils.isEmpty(username)){
            stringBuffer.append(" username = #{username}");
            isNeedAnd = true;
        }
        if (status!=null){
            if (isNeedAnd){
                stringBuffer.append(" and status = #{status}");
            }else {
                stringBuffer.append("  status = #{status}");
            }
        }

        String sql = stringBuffer.toString();
        if (sql.endsWith("where")){
            sql.replace("where", "");
        }else if (sql.endsWith("and")){
            sql.replace("and", "");
        }
        return sql;
    }
}
